package com.one.apartmentsystem.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.one.apartmentsystem.app.domain.ContractInfo;
import com.one.apartmentsystem.app.service.ContractInfoService;
import com.one.apartmentsystem.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 合同管理接口
 * @author mpk
 * @since 2024/8/4 11:54:19
 */
@RestController
@CrossOrigin
@RequestMapping("/app/contract")
public class ContractController {

    /**
     * 合同信息服务
     */
    @Autowired
    ContractInfoService contractInfoService;

    /**
     * 根据房屋ID获取合同信息
     *
     * @param houseId 房屋ID
     * @return 返回合同信息的Result对象
     */
    @GetMapping("/{houseId}")
    public Result getContract(@PathVariable String houseId) {
        // 根据房屋ID查询对应的合同信息
        ContractInfo houseInfo = contractInfoService.getOne(
                new LambdaQueryWrapper<ContractInfo>()
                        .eq(ContractInfo::getHouseId, houseId));

        // 返回查询到的合同信息
        return Result.ok(houseInfo);
    }

}
